<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>jQuery代理</title>
  <style>
    ul.list {
      width: 200px;
      padding: 10px;
      list-style: none;
      text-align: center;
    }
    ul.list.green {
      background-color: green;
      color: #fff;
    }
    ul.list li {
      border: 1px solid #ddd;
      padding: 5px;
      margin-bottom: 5px;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <ul class="list">
    <li>选项一</li>
    <li>选项二</li>
    <li>选项三</li>
  </ul>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script>
    // jQuery事件代理
    const list = document.querySelector('.list')
    list.addEventListener('click', function (e) {
      const target = e.target
      if (target.tagName === 'LI') {
        alert(target.innerHTML)
      }
    })
    // jQuery代理：$.proxy
    list.addEventListener('click', function () {
      setTimeout($.proxy(function () {
        $(this).addClass('green')
      }, this), 500)
    })
  </script>
</body>
</html>